<template>
  <div class="category-books">
    <h2>{{ category.name }}类书籍</h2>

    <!-- 书籍列表 -->
    <div class="books">
      <div class="book" v-for="(book, index) in books" :key="book.id">
        <div class="book-box">
          <img :src="book.cover" alt="book cover" />
          <div class="book-info">
            <h3>{{ book.title }}</h3>
            <p>作者：{{ book.author }}</p>
            <p>书籍介绍：{{ book.description }}</p>
            <button @click="goToComment(book)">查看评论</button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import axios from 'axios';
export default {
  data() {
    return {
      category: {},
      books: []
    };
  },
  mounted() {
    this.getCategoryBooks();
  },
  methods: {
    getCategoryBooks() {
      // 根据路由参数获取分类id
      const categoryId = this.$route.params.categoryId;

      // 发送请求获取该分类下的书籍数据
      // 假设后端接口为 '/api/category/${categoryId}/books'
	  //http://192.168.1.11:8080/v1/search/book?keyword=${keyword}
      axios.get(`http://127.0.0.1:8080/v1/category/${categoryId}/books`)
        .then(response => {
          this.category = response.data.category;
          this.books = response.data.books;
        })
        .catch(error => {
          console.log(error);
        });
    },
    goToComment(book) {
      // 跳转到书籍评论页面的逻辑
      // 假设跳转链接为 '/book/:bookId/comments'
      this.$router.push(`/book/${book.id}/comments`);
    }
  }
};
</script>

<style scoped>
.category-books {
  text-align: center;
}

.books {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 20px;
}

.book {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 10px;
}

.book img {
  width: 100px;
  height: 150px;
  margin-bottom: 10px;
}

.book-info {
  text-align: center;
}

button {
  margin-top: 10px;
}
.book-box {
  display: flex;
  align-items: center;
}

.book-info {
  margin-left: 20px;
}
</style>
<!-- 接下来，在你的路由配置文件（如router.js）中添加该组件的路由规则：

javascript
import CategoryBooks from './path/to/CategoryBooks.vue';

// Other routes...

{
  path: '/category/:categoryId',
  name: 'category-books',
  component: CategoryBooks
} -->